const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()

// 定义所有需要创建的集合
const collections = [
  'users',
  'activities',
  'goods',
  'member_levels',
  'orders',
  'activity_registrations',
  'addresses',
  'user_activity_relay',
  'banners',
  'activity_members',
  'vote_activity'
]

// 默认会员等级数据
const defaultMemberLevels = [
  {
    name: '普通会员',
    level: 1,
    upgradeCondition: {
      type: 'total_amount',
      value: 0
    },
    discountRate: 1.0,
    pointsRate: 1.0,
    rights: ['基础会员权益'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '银牌会员',
    level: 2,
    upgradeCondition: {
      type: 'total_amount',
      value: 1000
    },
    discountRate: 0.95,
    pointsRate: 1.1,
    rights: ['95折优惠', '积分加速1.1倍'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '黄金会员',
    level: 3,
    upgradeCondition: {
      type: 'total_amount',
      value: 5000
    },
    discountRate: 0.9,
    pointsRate: 1.2,
    rights: ['9折优惠', '积分加速1.2倍', '优先客服'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '铂金会员',
    level: 4,
    upgradeCondition: {
      type: 'total_amount',
      value: 10000
    },
    discountRate: 0.85,
    pointsRate: 1.3,
    rights: ['85折优惠', '积分加速1.3倍', '专属客服', '优先发货'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '钻石会员',
    level: 5,
    upgradeCondition: {
      type: 'total_amount',
      value: 20000
    },
    discountRate: 0.8,
    pointsRate: 1.5,
    rights: ['8折优惠', '积分加速1.5倍', '专属客服', '优先发货', '生日特权'],
    createdAt: new Date(),
    updatedAt: new Date()
  }
]

// 默认商品数据
const defaultGoods = [
  // 首页推荐商品
  {
    name: '北欧简约台灯',
    price: 299.99,
    originalPrice: 349.99,
    description: '简约设计，温馨照明',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsA.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsA.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '家居用品',
    categoryId: 1,
    stock: 50,
    sales: 128,
    recommended: 1, // 推荐商品
    status: 1, // 1-上架 0-下架
    specifications: [
      { name: '颜色', options: ['白色', '黑色', '原木色'], offset: [5, 0, 0]},
      { name: '尺寸', options: ['标准版', '加大版'], offset: [0, 0]}
    ],
    details: '采用北欧简约设计理念，优质材料制作，提供温馨舒适的照明体验。适合卧室、书房等多种场景使用。',
    tags: ['简约', '温馨', '护眼'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '手工陶瓷茶具',
    price: 199.99,
    originalPrice: 259.99,
    description: '传统工艺制作，品茶首选',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsA.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsA.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '茶具',
    categoryId: 2,
    stock: 30,
    sales: 89,
    recommended: 1, // 推荐商品
    status: 1,
    specifications: [
      { name: '套装', options: ['基础套装', '豪华套装'], offset: [0, 0] },
      { name: '颜色', options: ['青花', '白瓷', '黑陶'], offset: [0, 0, 0] }
    ],
    details: '采用传统手工工艺制作，每一件都是独一无二的艺术品。适合茶艺爱好者使用。',
    tags: ['手工', '传统', '艺术'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '有机棉床品',
    price: 399.99,
    originalPrice: 499.99,
    description: '100%有机棉，亲肤舒适',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsA.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsA.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '床上用品',
    categoryId: 3,
    stock: 25,
    sales: 156,
    recommended: 1, // 推荐商品
    status: 1,
    specifications: [
      { name: '尺寸', options: ['1.5m', '1.8m', '2.0m'], offset: [0, 0, 0]},
      { name: '颜色', options: ['纯白', '浅灰', '米色'], offset: [0, 0, 0]}
    ],
    details: '100%有机棉材质，通过国际有机认证，亲肤透气，给您最舒适的睡眠体验。',
    tags: ['有机', '舒适', '健康'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '智能蓝牙音箱',
    price: 149.99,
    originalPrice: 199.99,
    description: '高品质音效，无线连接',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsB.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsB.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '数码产品',
    categoryId: 4,
    stock: 80,
    sales: 234,
    recommended: 1, // 推荐商品
    status: 1,
    specifications: [
      { name: '颜色', options: ['黑色', '白色', '蓝色'], offset: [0, 0, 0]},
      { name: '版本', options: ['标准版', '专业版'], offset: [0, 0]}
    ],
    details: '支持蓝牙5.0连接，高保真音质，长续航设计，是您音乐生活的完美伴侣。',
    tags: ['智能', '音质', '便携'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '竹制收纳盒',
    price: 79.99,
    description: '环保材质，多功能收纳',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsB.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsB.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '收纳用品',
    categoryId: 5,
    stock: 60,
    sales: 78,
    recommended: 1, // 推荐商品
    status: 1,
    specifications: [
      { name: '尺寸', options: ['小号', '中号', '大号'], offset: [0, 0, 0]},
      { name: '款式', options: ['简约款', '复古款'], offset: [0, 0]}
    ],
    details: '采用天然竹材制作，环保健康，多格设计，满足不同收纳需求。',
    tags: ['环保', '收纳', '天然'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '精装艺术画册',
    price: 249.99,
    description: '收录经典艺术作品',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsB.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsB.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '图书',
    categoryId: 6,
    stock: 40,
    sales: 45,
    recommended: 1, // 推荐商品
    status: 1,
    specifications: [
      { name: '版本', options: ['中文版', '双语版'], offset: [0, 0] },
      { name: '装帧', options: ['精装', '平装'], offset: [0, 0]}
    ],
    details: '收录世界经典艺术作品，高清印刷，精美装帧，是艺术爱好者的珍藏之选。',
    tags: ['艺术', '收藏', '精装'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  // 商店页面商品（非推荐）
  {
    name: '培根厚蛋烧法风烧饼',
    price: 20.00,
    originalPrice: 31.00,
    description: '二件套',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsA.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsA.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '人气热卖',
    categoryId: 1,
    stock: 100,
    sales: 567,
    recommended: 0, // 非推荐商品
    status: 1,
    isNew: true,
    specifications: [
      { name: '套餐', options: ['单品', '套餐'], offset: [0, 0]}
    ],
    details: '精选培根配厚蛋烧，法式烧饼工艺，口感丰富，营养均衡。',
    tags: ['热卖', '新品', '营养'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '芝士厚蛋烧帕尼尼',
    price: 15.00,
    originalPrice: 25.00,
    description: '二件套',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsB.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsB.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '帕尼尼',
    categoryId: 2,
    stock: 80,
    sales: 234,
    recommended: 0,
    status: 1,
    specifications: [
      { name: '口味', options: ['原味', '香辣'], offset: [0, 0]}
    ],
    details: '浓郁芝士配厚蛋烧，帕尼尼面包香脆，口感层次丰富。',
    tags: ['芝士', '香脆', '美味'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '皮蛋瘦肉粥',
    price: 11.00,
    originalPrice: 15.50,
    description: '二件套',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsA.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsA.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '现熬好粥',
    categoryId: 3,
    stock: 50,
    sales: 189,
    recommended: 0,
    status: 1,
    isNew: true,
    specifications: [
      { name: '分量', options: ['小份', '大份'], offset: [0, 0]}
    ],
    details: '精选优质大米，配皮蛋瘦肉，慢火熬制，营养丰富。',
    tags: ['营养', '新品', '温补'],
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    name: '蓬松酥脆法风烧饼',
    price: 18.50,
    description: '更多花样',
    image: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/cover/goodsA.jpg',
    images: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/banners/goodsA.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/goods/details/goodsA.jpg'
    ],
    category: '法风烧饼',
    categoryId: 4,
    stock: 70,
    sales: 123,
    recommended: 0,
    status: 1,
    specifications: [
      { name: '口味', options: ['原味', '芝麻', '红豆'], offset: [0, 0, 0]}
    ],
    details: '法式工艺制作，外酥内软，多种口味选择，满足不同喜好。',
    tags: ['酥脆', '法式', '多样'],
    createdAt: new Date(),
    updatedAt: new Date()
  }
]

// 默认活动数据 - 添加了 type 字段
const defaultActivities = [
  {
    eventTitle: '一起来打鼓',
    eventName: '非洲鼓派对',
    subtitle: '感受非洲鼓的节拍魅力',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/activityA.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/activityA.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/activityB.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/activityA.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/activityB.jpg'
    ],
    recommended: 1,
    tag1: '热门活动',
    tag2: '立即参与',
    status: '报名中',
    statusColor: '#07C160',
    category: 'music',
    type: '音乐演出',
    signedUpCount: 45,
    maxParticipants: 100,
    buttonText: '去报名',
    imageWidth: 400,
    imageHeight: 300,
    price: 0,
    startTime: '2024-04-20 14:00',
    endTime: '2024-04-20 17:00',
    location: '文化艺术中心音乐厅',
    latitude: 39.9042,
    longitude: 116.4074,
    address: '北京市朝阳区文化艺术中心音乐厅',
    organizer: '优AI文化发展中心',
    tags: ['音乐体验', '免费活动', '团体活动'],
    description: '非洲鼓派对是一场充满节奏感的音乐体验活动。参与者将学习基本的非洲鼓演奏技巧，感受原始而纯粹的音乐魅力。活动适合所有年龄段，无需音乐基础。',
    highlights: [
      '专业非洲鼓导师现场教学',
      '提供专业非洲鼓设备',
      '小组合奏体验',
      '录制演奏视频留念'
    ],
    schedule: [
      { time: '14:00-14:30', content: '签到及设备介绍' },
      { time: '14:30-15:30', content: '基础节拍学习' },
      { time: '15:30-16:30', content: '小组练习' },
      { time: '16:30-17:00', content: '合奏表演及录制' }
    ],
    requirements: [
      '无需音乐基础，欢迎所有人参与',
      '请穿着舒适的服装',
      '建议提前10分钟到场',
      '活动全程请保持手机静音'
    ],
    contact: {
      phone: '400-123-4567',
      wechat: 'youai_music',
      email: 'music@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    eventTitle: '环保从我做起',
    eventName: '环保亲子活动',
    subtitle: '培养环保意识，共建绿色家园',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/04.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/04.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/01.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/04.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/01.jpg'
    ],
    recommended: 1,
    tag1: '知识分享',
    tag2: '文化交流',
    status: '报名中',
    statusColor: '#07C160',
    category: 'education',
    type: '教育培训',
    signedUpCount: 78,
    maxParticipants: 80,
    buttonText: '立即报名',
    imageWidth: 400,
    imageHeight: 520,
    price: 0,
    startTime: '2024-04-21 09:00',
    endTime: '2024-04-21 12:00',
    location: '生态公园环保教育基地',
    latitude: 39.8888,
    longitude: 116.3888,
    address: '北京市海淀区生态公园环保教育基地',
    organizer: '优AI文化发展中心',
    tags: ['环保教育', '亲子活动', '免费活动'],
    description: '环保亲子活动旨在通过寓教于乐的方式，让家长和孩子共同学习环保知识，培养环保意识。活动包括环保知识讲座、废物利用手工制作、植物种植体验等环节。',
    highlights: [
      '环保专家现场讲解环保知识',
      '亲子废物利用手工制作',
      '植物种植体验活动',
      '环保承诺签名仪式'
    ],
    schedule: [
      { time: '09:00-09:30', content: '签到及活动介绍' },
      { time: '09:30-10:30', content: '环保知识讲座' },
      { time: '10:30-11:30', content: '废物利用手工制作' },
      { time: '11:30-12:00', content: '植物种植及总结' }
    ],
    requirements: [
      '适合3-12岁儿童及家长参与',
      '请自带水杯，减少塑料垃圾',
      '建议穿着便于活动的服装',
      '请准备一些废旧材料用于手工制作'
    ],
    contact: {
      phone: '400-123-4568',
      wechat: 'youai_eco',
      email: 'eco@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    eventTitle: '现代艺术展',
    eventName: '当代艺术特展',
    subtitle: '探索当代艺术的无限可能',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/activityB.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/activityB.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/01.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/activityB.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/01.jpg'
    ],
    recommended: 1,
    tag1: '艺术欣赏',
    tag2: '文化体验',
    status: '进行中',
    statusColor: '#4A90E2',
    category: 'exhibition',
    type: '展览展会',
    signedUpCount: 156,
    maxParticipants: 200,
    buttonText: '预约参观',
    imageWidth: 400,
    imageHeight: 280,
    price: 50,
    startTime: '2024-04-10 10:00',
    endTime: '2024-04-30 18:00',
    location: '现代艺术博物馆',
    latitude: 39.9152,
    longitude: 116.3974,
    address: '北京市东城区现代艺术博物馆',
    organizer: '现代艺术博物馆',
    tags: ['艺术展览', '文化体验', '现代艺术'],
    description: '当代艺术特展汇集了国内外知名艺术家的精品力作，涵盖绘画、雕塑、装置艺术等多种形式，为观众呈现当代艺术的多元面貌和创新精神。',
    highlights: [
      '50余件当代艺术精品',
      '知名艺术家现场导览',
      '互动体验区域',
      '艺术家见面会'
    ],
    schedule: [
      { time: '10:00-12:00', content: '自由参观时间' },
      { time: '14:00-15:00', content: '专家导览讲解' },
      { time: '15:00-16:00', content: '互动体验活动' },
      { time: '16:00-18:00', content: '自由参观时间' }
    ],
    requirements: [
      '适合所有年龄段参观',
      '请保持安静，不要大声喧哗',
      '禁止触摸展品',
      '可以拍照，但请关闭闪光灯'
    ],
    contact: {
      phone: '400-123-4567',
      wechat: 'youai_culture',
      email: 'contact@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    eventTitle: '夏日草地音乐节',
    eventName: '2025夏日音乐节',
    subtitle: '在草地上享受音乐的美好',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/03.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/03.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/02.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/03.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/02.jpg'
    ],
    recommended: 0,
    tag1: '音乐盛宴',
    tag2: '户外派对',
    status: '即将开始',
    statusColor: '#FF9500',
    category: 'music',
    type: '音乐演出',
    signedUpCount: 89,
    maxParticipants: 500,
    buttonText: '购票参加',
    imageWidth: 400,
    imageHeight: 450,
    price: 120,
    startTime: '2024-07-15 16:00',
    endTime: '2024-07-15 22:00',
    location: '城市中央公园草坪',
    latitude: 39.9289,
    longitude: 116.4201,
    address: '北京市朝阳区城市中央公园草坪',
    organizer: '优AI文化发展中心',
    tags: ['音乐节', '户外活动', '夏日派对'],
    description: '夏日草地音乐节是一场集音乐、美食、艺术于一体的户外盛会。在绿意盎然的草坪上，与朋友们一起享受音乐带来的快乐时光。',
    highlights: [
      '多位知名音乐人现场演出',
      '美食摊位和饮品供应',
      '草坪野餐体验',
      '音乐互动游戏'
    ],
    schedule: [
      { time: '16:00-17:00', content: '入场及草坪野餐时间' },
      { time: '17:00-18:30', content: '开场乐队表演' },
      { time: '18:30-19:30', content: '晚餐时间' },
      { time: '19:30-21:30', content: '主要艺人演出' },
      { time: '21:30-22:00', content: '全场大合唱' }
    ],
    requirements: [
      '适合所有年龄段参与',
      '建议携带野餐垫和防晒用品',
      '可自带食物和饮料',
      '请爱护环境，不要乱扔垃圾'
    ],
    contact: {
      phone: '400-123-4567',
      wechat: 'youai_culture',
      email: 'contact@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    eventTitle: '国际美食文化节',
    eventName: '环球美食嘉年华',
    subtitle: '品味世界，文化交融',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/activityA.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/activityA.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/04.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/activityA.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/04.jpg'
    ],
    recommended: 0,
    tag1: '美食体验',
    tag2: '文化交流',
    status: '报名中',
    statusColor: '#07C160',
    category: 'food',
    type: '美食体验',
    signedUpCount: 234,
    maxParticipants: 300,
    buttonText: '立即报名',
    imageWidth: 400,
    imageHeight: 350,
    price: 80,
    startTime: '2024-05-01 11:00',
    endTime: '2024-05-01 20:00',
    location: '国际会展中心',
    latitude: 39.9175,
    longitude: 116.3972,
    address: '北京市朝阳区国际会展中心',
    organizer: '国际文化交流协会',
    tags: ['美食节', '文化交流', '国际美食'],
    description: '国际美食文化节汇聚了来自世界各地的特色美食，让您在品尝美味的同时，感受不同国家和地区的文化魅力。',
    highlights: [
      '20多个国家的特色美食',
      '现场烹饪表演',
      '文化展示和表演',
      '美食制作体验课程'
    ],
    schedule: [
      { time: '11:00-12:00', content: '开幕式及文化表演' },
      { time: '12:00-14:00', content: '午餐时间及美食品尝' },
      { time: '14:00-16:00', content: '烹饪表演及体验' },
      { time: '16:00-18:00', content: '文化交流活动' },
      { time: '18:00-20:00', content: '晚餐时间及闭幕' }
    ],
    requirements: [
      '适合所有年龄段参与',
      '建议空腹前来，尽情品尝美食',
      '请注意食物过敏信息',
      '现场支持多种支付方式'
    ],
    contact: {
      phone: '400-123-4567',
      wechat: 'youai_culture',
      email: 'contact@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    eventTitle: '城市马拉松',
    eventName: '2025城市马拉松',
    subtitle: '挑战自我，超越极限',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/02.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/02.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/01.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/02.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/01.jpg'
    ],
    recommended: 0,
    tag1: '体育竞技',
    tag2: '健康生活',
    status: '报名即将截止',
    statusColor: '#FF3B30',
    category: 'sports',
    type: '运动健身',
    signedUpCount: 567,
    maxParticipants: 1000,
    buttonText: '立即报名',
    imageWidth: 400,
    imageHeight: 480,
    price: 100,
    startTime: '2024-06-01 07:00',
    endTime: '2024-06-01 12:00',
    location: '城市体育中心',
    latitude: 39.9021,
    longitude: 116.3822,
    address: '北京市西城区城市体育中心',
    organizer: '城市体育局',
    tags: ['马拉松', '体育竞技', '健康运动'],
    description: '城市马拉松是一项展现城市活力和市民健康生活态度的大型体育赛事。无论您是专业跑者还是业余爱好者，都能在这里找到属于自己的挑战。',
    highlights: [
      '全程、半程、迷你马拉松多种选择',
      '专业计时和成绩证书',
      '沿途补给和医疗保障',
      '完赛奖牌和纪念品'
    ],
    schedule: [
      { time: '06:00-07:00', content: '检录和热身准备' },
      { time: '07:00-07:30', content: '开幕式和起跑仪式' },
      { time: '07:30-12:00', content: '比赛进行时间' },
      { time: '12:00-13:00', content: '颁奖仪式' }
    ],
    requirements: [
      '年满18岁，身体健康',
      '需提供健康证明',
      '请穿着专业跑步装备',
      '比赛当天请提前到达'
    ],
    contact: {
      phone: '400-123-4567',
      wechat: 'youai_culture',
      email: 'contact@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    eventTitle: '书法体验课',
    eventName: '毛笔书法入门',
    subtitle: '传承书法艺术，感受文字之美',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/01.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/01.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/activityB.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/01.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/activityB.jpg'
    ],
    recommended: 0,
    tag1: '传统文化',
    tag2: '艺术体验',
    status: '报名中',
    statusColor: '#07C160',
    category: 'culture',
    type: '文化艺术',
    signedUpCount: 34,
    maxParticipants: 25,
    buttonText: '立即报名',
    imageWidth: 400,
    imageHeight: 320,
    price: 60,
    startTime: '2024-04-25 14:00',
    endTime: '2024-04-25 17:00',
    location: '传统文化艺术中心',
    latitude: 39.9136,
    longitude: 116.4041,
    address: '北京市东城区传统文化艺术中心',
    organizer: '书法协会',
    tags: ['书法艺术', '传统文化', '艺术体验'],
    description: '书法体验课程由资深书法老师亲自指导，从基础笔画开始，让学员感受中华传统书法艺术的魅力，体验文字书写的乐趣。',
    highlights: [
      '资深书法老师一对一指导',
      '提供专业书法用具',
      '学习基础笔画和字体结构',
      '完成个人书法作品'
    ],
    schedule: [
      { time: '14:00-14:30', content: '签到及书法文化介绍' },
      { time: '14:30-15:30', content: '基础笔画练习' },
      { time: '15:30-16:30', content: '字体结构学习' },
      { time: '16:30-17:00', content: '作品创作及点评' }
    ],
    requirements: [
      '适合所有年龄段参与',
      '无需书法基础',
      '请穿着深色衣服，避免墨汁污染',
      '保持安静的学习环境'
    ],
    contact: {
      phone: '400-123-4567',
      wechat: 'youai_culture',
      email: 'contact@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    eventTitle: '户外徒步',
    eventName: '山地徒步探险',
    subtitle: '亲近自然，挑战自我',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/activityB.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/activityB.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/03.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/activityB.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/03.jpg'
    ],
    recommended: 0,
    tag1: '户外运动',
    tag2: '健康生活',
    status: '报名中',
    statusColor: '#07C160',
    category: 'outdoor',
    type: '户外活动',
    signedUpCount: 89,
    maxParticipants: 40,
    buttonText: '立即报名',
    imageWidth: 400,
    imageHeight: 400,
    price: 150,
    startTime: '2024-05-10 08:00',
    endTime: '2024-05-10 16:00',
    location: '青山国家森林公园',
    latitude: 39.9565,
    longitude: 116.3132,
    address: '北京市昌平区青山国家森林公园',
    organizer: '户外运动俱乐部',
    tags: ['户外徒步', '自然探索', '团队活动'],
    description: '山地徒步探险活动将带领大家走进大自然，在专业领队的带领下，体验徒步的乐趣，欣赏山林美景，呼吸新鲜空气。',
    highlights: [
      '专业户外领队全程陪同',
      '欣赏原始森林风光',
      '团队协作挑战项目',
      '户外野餐体验'
    ],
    schedule: [
      { time: '08:00-09:00', content: '集合出发及安全讲解' },
      { time: '09:00-12:00', content: '山地徒步第一段' },
      { time: '12:00-13:00', content: '山顶野餐休息' },
      { time: '13:00-15:00', content: '下山徒步' },
      { time: '15:00-16:00', content: '总结分享及返程' }
    ],
    requirements: [
      '年龄18-55岁，身体健康',
      '有一定的体能基础',
      '请穿着专业户外装备',
      '自备充足的水和食物'
    ],
    contact: {
      phone: '400-123-4567',
      wechat: 'youai_culture',
      email: 'contact@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  },
  {
    eventTitle: '咖啡品鉴会',
    eventName: '精品咖啡品鉴',
    subtitle: '品味咖啡文化，享受慢生活',
    bannerImage: 'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/cover/activityA.jpg',
    bannerImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/activityA.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/banners/01.jpg'
    ],
    detailImages: [
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/activityA.jpg',
      'cloud://shengyi-cloudbase-4e8hy10f8ba1e2.7368-shengyi-cloudbase-4e8hy10f8ba1e2-1372738167/shengyi_miniprogram/activities/details/01.jpg'
    ],
    recommended: 0,
    tag1: '生活品味',
    tag2: '文化交流',
    status: '报名中',
    statusColor: '#07C160',
    category: 'food',
    type: '美食体验',
    signedUpCount: 56,
    maxParticipants: 30,
    buttonText: '立即报名',
    imageWidth: 400,
    imageHeight: 360,
    price: 120,
    startTime: '2024-04-28 15:00',
    endTime: '2024-04-28 18:00',
    location: '精品咖啡馆',
    latitude: 39.9075,
    longitude: 116.4170,
    address: '北京市朝阳区三里屯精品咖啡馆',
    organizer: '咖啡文化协会',
    tags: ['咖啡品鉴', '生活品味', '文化交流'],
    description: '精品咖啡品鉴会邀请专业咖啡师为大家介绍不同产地、不同烘焙程度的咖啡特色，让参与者在品尝的过程中了解咖啡文化。',
    highlights: [
      '多种精品咖啡品尝',
      '专业咖啡师现场讲解',
      '咖啡制作技巧分享',
      '咖啡文化知识交流'
    ],
    schedule: [
      { time: '15:00-15:30', content: '签到及咖啡文化介绍' },
      { time: '15:30-16:30', content: '精品咖啡品鉴' },
      { time: '16:30-17:30', content: '咖啡制作体验' },
      { time: '17:30-18:00', content: '交流分享' }
    ],
    requirements: [
      '适合咖啡爱好者参与',
      '请勿空腹参加',
      '如有咖啡因过敏请提前告知',
      '保持安静的品鉴环境'
    ],
    contact: {
      phone: '400-123-4567',
      wechat: 'youai_culture',
      email: 'contact@youai.com'
    },
    createdAt: new Date(),
    updatedAt: new Date()
  }
]

// 默认投票活动数据
const defaultVoteActivities = [
  {
    _id: 'vote_001',
    _activityId: 'activity_001',
    title: '你最喜欢的非洲鼓演奏风格',
    description: '参与投票，告诉我们你最喜欢哪种非洲鼓演奏风格，帮助我们策划更精彩的活动！',
    backgroundImage: 'cloud://cloudbase-1g29vs061fa4f865.636c-cloudbase-1g29vs061fa4f865-1370648540/image/test/activityA.jpg',
    options: [
      {
        id: 1,
        name: '传统风格',
        avatar: 'cloud://cloudbase-1g29vs061fa4f865.636c-cloudbase-1g29vs061fa4f865-1370648540/image/test/traditional.jpg',
        votes: 0
      },
      {
        id: 2,
        name: '现代融合',
        avatar: 'cloud://cloudbase-1g29vs061fa4f865.636c-cloudbase-1g29vs061fa4f865-1370648540/image/test/modern.jpg',
        votes: 0
      },
      {
        id: 3,
        name: '爵士风格',
        avatar: 'cloud://cloudbase-1g29vs061fa4f865.636c-cloudbase-1g29vs061fa4f865-1370648540/image/test/jazz.jpg',
        votes: 0
      },
      {
        id: 4,
        name: '流行改编',
        avatar: 'cloud://cloudbase-1g29vs061fa4f865.636c-cloudbase-1g29vs061fa4f865-1370648540/image/test/pop.jpg',
        votes: 0
      }
    ],
    endTime: new Date('2025-09-30T23:59:59'),
    createdAt: new Date(),
    updatedAt: new Date()
  }
]

exports.main = async (event, context) => {
  console.log('开始初始化数据库...')
  
  try {
    const results = {
      collections: [],
      indexes: [],
      memberLevels: [],
      activities: [],
      errors: []
    }

    // 1. 创建所有集合
    console.log('1. 开始创建集合...')
    for (const collectionName of collections) {
      try {
        await db.createCollection(collectionName)
        results.collections.push({ name: collectionName, status: 'created' })
        console.log(`✓ 集合 ${collectionName} 创建成功`)
      } catch (error) {
        if (error.errCode === -502005) {
          // 集合已存在
          results.collections.push({ name: collectionName, status: 'already_exists' })
          console.log(`⚠ 集合 ${collectionName} 已存在`)
        } else {
          results.errors.push({ type: 'collection', name: collectionName, error: error.message })
          console.error(`✗ 集合 ${collectionName} 创建失败:`, error)
        }
      }
    }

    // 2. 初始化会员等级数据
    console.log('\n2. 开始初始化会员等级数据...')
    try {
      const memberLevelsCollection = db.collection('member_levels')
      
      // 检查是否已存在数据
      const existingCount = await memberLevelsCollection.count()
      
      if (existingCount.total === 0) {
        // 批量添加默认会员等级
        const addResult = await memberLevelsCollection.add({
          data: defaultMemberLevels
        })
        
        results.memberLevels = addResult._ids.map((id, index) => ({
          id: id,
          level: defaultMemberLevels[index].level,
          name: defaultMemberLevels[index].name,
          status: 'created'
        }))
        console.log(`✓ 成功添加 ${addResult._ids.length} 个会员等级`)
      } else {
        console.log(`⚠ 会员等级数据已存在，跳过初始化`)
        results.memberLevels.push({ status: 'already_exists', count: existingCount.total })
      }
    } catch (error) {
      results.errors.push({ 
        type: 'member_levels', 
        error: error.message 
      })
      console.error('✗ 会员等级数据初始化失败:', error)
    }

    // 3. 初始化商品数据
    console.log('\n3. 开始初始化商品数据...')
    try {
      const goodsCollection = db.collection('goods')
      
      // 检查是否已存在数据
      const existingGoodsCount = await goodsCollection.count()
      
      if (existingGoodsCount.total === 0) {
        // 批量添加商品数据
        const addGoodsResult = await goodsCollection.add({
          data: defaultGoods
        })
        
        results.goods = addGoodsResult._ids.map((id, index) => ({
          id: id,
          name: defaultGoods[index].name,
          category: defaultGoods[index].category,
          recommended: defaultGoods[index].recommended,
          status: 'created'
        }))
        console.log(`✓ 成功添加 ${addGoodsResult._ids.length} 个商品`)
      } else {
        console.log(`⚠ 商品数据已存在，跳过初始化`)
        results.goods = [{ status: 'already_exists', count: existingGoodsCount.total }]
      }
    } catch (error) {
      results.errors.push({ 
        type: 'goods', 
        error: error.message 
      })
      console.error('✗ 商品数据初始化失败:', error)
    }

    // 4. 初始化活动数据
    console.log('\n4. 开始初始化活动数据...')
    try {
      const activitiesCollection = db.collection('activities')
      
      // 检查是否已存在数据
      const existingActivitiesCount = await activitiesCollection.count()
      
      if (existingActivitiesCount.total === 0) {
        // 批量添加活动数据
        const addActivitiesResult = await activitiesCollection.add({
          data: defaultActivities
        })
        
        results.activities = addActivitiesResult._ids.map((id, index) => ({
          id: id,
          title: defaultActivities[index].eventTitle,
          type: defaultActivities[index].type,
          status: 'created'
        }))
        console.log(`✓ 成功添加 ${addActivitiesResult._ids.length} 个活动`)
      } else {
        console.log(`⚠ 活动数据已存在，跳过初始化`)
        results.activities = [{ status: 'already_exists', count: existingActivitiesCount.total }]
      }
    } catch (error) {
      results.errors.push({ 
        type: 'activities', 
        error: error.message 
      })
      console.error('✗ 活动数据初始化失败:', error)
    }

    // 5. 初始化投票活动数据
    console.log('\n5. 开始初始化投票活动数据...')
    try {
      const voteActivitiesCollection = db.collection('vote_activity')
      
      // 检查是否已存在数据
      const existingVoteActivitiesCount = await voteActivitiesCollection.count()
      
      if (existingVoteActivitiesCount.total === 0) {
        // 批量添加投票活动数据
        const addVoteActivitiesResult = await voteActivitiesCollection.add({
          data: defaultVoteActivities
        })
        
        results.voteActivities = addVoteActivitiesResult._ids.map((id, index) => ({
          id: id,
          title: defaultVoteActivities[index].title,
          status: 'created'
        }))
        console.log(`✓ 成功添加 ${addVoteActivitiesResult._ids.length} 个投票活动`)
      } else {
        console.log(`⚠ 投票活动数据已存在，跳过初始化`)
        results.voteActivities = [{ status: 'already_exists', count: existingVoteActivitiesCount.total }]
      }
    } catch (error) {
      results.errors.push({ 
        type: 'vote_activities', 
        error: error.message 
      })
      console.error('✗ 投票活动数据初始化失败:', error)
    }

    // 6. 输出总结信息
    console.log('\n=== 数据库初始化完成 ===')
    console.log(`创建集合: ${results.collections.filter(r => r.status === 'created').length} 个`)
    console.log(`已存在集合: ${results.collections.filter(r => r.status === 'already_exists').length} 个`)
    console.log(`添加会员等级: ${results.memberLevels.filter(r => r.status === 'created').length} 个`)
    console.log(`添加商品: ${results.goods ? results.goods.filter(r => r.status === 'created').length : 0} 个`)
    console.log(`添加活动: ${results.activities.filter(r => r.status === 'created').length} 个`)
    console.log(`添加投票活动: ${results.voteActivities ? results.voteActivities.filter(r => r.status === 'created').length : 0} 个`)
    
    if (results.errors.length > 0) {
      console.warn(`\n⚠ 遇到 ${results.errors.length} 个错误:`)
      results.errors.forEach(error => {
        console.warn(`  - ${error.type}: ${error.error}`)
      })
    }

    return {
      success: true,
      message: '数据库初始化完成，包含商品数据和活动数据',
      results: results,
      timestamp: new Date().toISOString()
    }

  } catch (error) {
    console.error('数据库初始化失败:', error)
    return {
      success: false,
      error: error.message,
      timestamp: new Date().toISOString()
    }
  }
}